<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #app button {
            margin: 5px;
            padding: 5px 10px;
        }

        .box {
            float: left;
            width: 200px;
            height: 200px;
            background-color: var(--bg);
            text-align: center;
            line-height: 200px;
            font-size: 60px;
        }
    </style>
</head>

<body>

    <div id="app">
        <h3>姓名是：{{name}}</h3>
        <h3>年龄是：{{ age }} <span>title的值是：{{title}}</span> </h3>
        <h3>info.a的值是：{{info.a}}</h3>
        <div>name的值：<input type="text" v-model="name" /></div>
        <div>info.a的值：<input type="text" v-model="info.a" /></div>
        <br>

        <h3><button @click="add1">点击num1</button> <span>num1的值是：{{num1}}</span> </h3>
        <h3><button @click="add2">点击num2</button> <span>num2的值是：{{num2}}</span> </h3>
        <h3> computed total 的值为：{{total}} </h3>
        <br>
        <button @click="box1">点击1</button>
        <button @click="box2">点击2</button>
        <button @click="box3">点击3</button>
        <button @click="box4">点击4</button>
        <br>
        <div class="box" v-show='showbox1' style="--bg:red">1</div>
        <div class="box" v-if='ifbox2' style="--bg:purple">2</div>
        <div class="box" v-if='ifbox3' style="--bg:yellow">3</div>
        <div class="box" v-show='showbox4' style="--bg:brown">4</div>

    </div>
    <script src="computed.js"></script>
    <script src="index.js"></script>
    <script>


        let vm = new Vue({
            el: '#app',
            data() {
                return {
                    name: 'zs',
                    age: 20,
                    showbox1: false,
                    ifbox2: false,
                    ifbox3: false,
                    showbox4: false,
                    info: {
                        a: 'a1',
                        c: 'c1'
                    },
                    title: '学生列表',
                    classNum: 1,
                    num1: 1,
                    num2: 2
                }
            },
            methods: {
                add1() {
                    this.num1++
                },
                add2() {
                    this.num2 += 2
                },
                box1() {
                    this.showbox1 = !this.showbox1;
                },
                box2() {
                    this.ifbox2 = !this.ifbox2;
                },
                box3() {
                    this.ifbox3 = !this.ifbox3;
                },
                box4() {
                    this.showbox4 = !this.showbox4;
                },
            },
            computed: {
                total() {
                    console.log('total');
                    return this.num1 + this.num2

                }
            },
            watch: {
                num1(newVal, oldVal) {
                    console.log('key', 'newVal', 'oldVal');
                    console.log('num1', newVal, oldVal);
                },
                num2(newVal, oldVal) {
                    console.log('key', 'newVal', 'oldVal');
                    console.log('num2', newVal, oldVal);
                }
            }
        });
        console.log(vm)

    </script>

</body>

</html>